import os


def code_lines_count(path):
    code_lines = 0
    comm_lines = 0
    space_lines = 0
    for root,dirs,files in os.walk(path):
        for item in files:
            file_abs_path = os.path.join(root,item)
            postfix = os.path.splitext(file_abs_path)[1]
            if postfix == '.py':


                with open(file_abs_path,'r', encoding='utf-8') as fp:
                    while True:
                        line = fp.readline()
                        if not line:

                            break
                        elif line.strip().startswith('#'):

                            comm_lines += 1
                        elif line.strip().startswith("'''") or line.strip().startswith('"""'):
                            comm_lines += 1
                         
                        elif line.strip():

                            code_lines += 1
                        else:

                            space_lines +=1

    return code_lines,comm_lines,space_lines

if __name__ == '__main__':
    abs_dir = os.getcwd()
    x,y,z = code_lines_count(abs_dir)
    print(f"代码:{x-45},空行{z} 注释:{y} 总计{x+y+z-45}")